<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */
 
$keyword = urldecode($keyword);
$keyword = iconv('Windows-1252', 'UTF-8', $keyword);
$keyword = $db->real_escape_string($keyword);

$query = $db->query("
(
				SELECT id, title, pretext, text, date,
					MATCH (title, pretext, text)
					AGAINST ('" . $keyword . "' IN BOOLEAN MODE) AS result1 ,
					(
						(3 * (
							MATCH (title)
							AGAINST ('" . $keyword . "')
							)
						) + (2 *(
							MATCH (pretext)
							AGAINST ('" . $keyword . "')
							)
						) + (
							MATCH (text)
							AGAINST ('" . $keyword . "')
						)
					) AS result2
					FROM {prefix}articles WHERE published = 1 HAVING result1 > 0
			)
					ORDER BY result1 DESC, result2 DESC
			");
			if((int)$query->num_rows == 0){
				Text::h2( Lang::getFront('com_search', 'not_found') );
				Text::p( Lang::getFront('com_search', 'you_search', array($keyword)) );
			}else{
   				$seoParser = new SeoUrl();
				Text::h2( Lang::getFront('com_search', 'found', array((int)$query->num_rows)) );
				echo '<ul>';
				while($result = $query->fetch_array()){
					$url = $seoParser->Parse($result['title']);
					echo '<li><a href="{url}index.php?q=content/'.$result['id']. '-' . $seoParser->result .'">'.$result['title'].'</a></li>';
				}
				echo '</ul>';
			}

?>